<template>
  <view class="container" :style="[`background-image: url('${getImageUrl('v-bg.png')} ');`]">
    <!-- 扫一扫的 tabbar 页面占位 -->
    <UFoooter></UFoooter>
  </view>
</template>

<script>
import UFoooter from '@/components/uTabbar.vue'
export default {
  components: {
    UFoooter
  },
  data() {
    return {
      isClose: false,
      isFirst: true
    }
  },
  onShow() {
    this.scanCode()
  },
  created() {},
  onBackPress() {
    uni.switchTab({
      url: '/pages/index/index'
    })
  },
  onHide() {
    uni.switchTab({
      url: '/pages/index/index'
    })
  },
  methods: {
    scanCode() {
      const app = this
      if (!app.isFirst) {
        return
      }
      app.isFirst = false
      // 允许从相机和相册扫码
      uni.scanCode({
        // scanType: ['QR_CODE'], //条形码
        success: function (res) {
          console.debug('条码内容：' + res.result)
          // 扫描到的信息
          if (res.result) {
            app.isFirst = true
            uni.reLaunch({
              url: '/pages/index/splash?q=' + encodeURIComponent(res.result)
            })
          }
        },
        fail: function (res) {
          console.warn('扫码失败：', res)
          app.isClose = true
          app.toIndex()
        }
      })
    },
    toIndex() {
      this.isFirst = true
      if (this.isClose) {
        uni.switchTab({
          url: '/pages/index/index'
        })
      }
    }
  }
}
</script>

<style>
.container {
  height: 100vh;
  position: relative;
  background-position: center;
  background-size: cover;
}
</style>
